import { Entity,PrimaryGeneratedColumn,Column, BaseEntity, ManyToOne,JoinColumn, ManyToMany, JoinTable } from 'typeorm'
import { User } from './user'
import { Article } from './article'

@Entity({name:'tags'})
export class Tag extends BaseEntity {
    @PrimaryGeneratedColumn()
    readonly id!: number

    @Column()
    title!: string;

    @Column()
    icon!: string;

    @Column()
    follow_count!: number;

    @Column()
    article_count!: number;

    @ManyToMany(()=> User, user => {
        caseade:true
    })

    @JoinTable({
        name: 'tags_users_rel',
        joinColumns: [
            { name: 'tag_id',  },
        ],
        inverseJoinColumns: [
            { name: 'user_id', },
        ]
    })

    users!: User[];

    @ManyToMany(()=> Article, article => article.tags)

    @JoinTable({
        name: 'articles_tags_rel',
        joinColumns: [
            { name: 'tag_id',  },
        ],
        inverseJoinColumns: [
            { name: 'article_id', },
        ]
    })

    articles!: Article[];

   
}